﻿using System;

namespace SPFluid.Core.Validation.Extensions
{
    public static class ObjectValidtorExtensions
    {
        public static IGuard<T> Is<T>(this IGuard<T> guard, Type type)
        {
            if (!type.IsInstanceOfType(guard.Argument.Value))
            {
                guard.ExceptionHandler.ThrowArgumentException(string.Format("Value is not of type '{0}'", type.Name));
            }

            return guard;
        }

        public static IGuard<T> IsNotDefault<T>(this IGuard<T> guard)
        {
            if (default(T).Equals(guard.Argument.Value))
            {
                guard.ExceptionHandler.ThrowArgumentException("Value cannot be the default value.");
            }

            return guard;
        }

        public static IGuard<T> IsTrue<T>(this IGuard<T> guard, Func<T, bool> booleanFunction, string exceptionMessage)
        {
            if (!booleanFunction(guard.Argument.Value))
            {
                guard.ExceptionHandler.ThrowArgumentException(exceptionMessage);
            }

            return guard;
        } 
    }
}